t
A Persistent Database and Local Methods

*528*
While the Folks Database is fluidly creating new Person objects and giving them names, these folks appear to be falling off the edge: they exist for a moment at the root of the birth operation in Add, but then they disappear.

Your next design goal is to collect these Person objects in a location where they can be stored and accessed whenever you want. That is, you want to turn your application into a real database using a Prograph persistent.*825*

______________________________________________________________________________________________________________________________________
NOTE: Prograph provides a special kind of object called a persistent. As its name suggests, persistents persist. When you save the application you are working on, persistents and their contents are saved along with the classes and current state of your application. All this information is saved in one file. Transient objects, like the Persons you have just created and seemingly “added into the RAM ether” are permanently lost between sessions.

While a persistent can be made any kind of Prograph object, it is often created as a list object. You can then store all kinds of things in the persistent list. You retrieve, manipulate, and inspect the contents of persistent lists with Prograph’s powerful*526* list-processing primitives. Beside holding collections of strings, numbers, and other basic data, lists can be made up of objects. You can even store other lists in a list. And you can store any combination of various kinds of objects, all in the same list. A persistent-list object, People, is a convenient way to turn your Folks Database into a real database. The storage limitations of your database depend on available RAM. If you wanted to create a really huge database, you would use external files and Prograph’s file-accessing primitives, or Prograph’s datafile primitives.
-----------------------------------------------------------

u Select Persistents *656**802**829**1186*from the Windows menu.

u Command click in the Persistents *664*window. A new, unnamed Persistent icon appears.*826*

u Type People and double-click on the Persistent icon to open its Value window.

u Scroll the upper left list to the list entry and click to select it. The right-side pane displays the parentheses of a new, empty list.

u Click OK to close the Value window. Close the Persistents window.

u Type Betty in the Name field of the Folks Database window and press the Add button to bring up the Add execution window. 

u Double-click the execution window to open the Add case window.

u *1097**428*With the crosshair cursor in the upper left corner, just below the input bar, click-drag a marquee to enclose all the operation icons in the Add method. (See ∂ in the figure below.) Do not include the input or output bars. Release the mouse button. *970*The enclosed icons are selected. If you miss any or accidentally capture an input or output bar, Shift-click on the wanted or unwanted icon to toggle its selection status.

u Select Opers to Local *799**807*in the Opers menu (see ∑). The selected operations disappear. They are replaced by an unnamed Local operation icon (see ∏).

u Type Make a Named Person and press Return. Drag the operation up closer to the root of the input bar connected to the new Local *653* operation (see π).

___________________________________________________________
NOTE: Local operations are like complexity-hiding capsules. A Local operation contains a network of *244*dataflow operations and has its own input and output bars. A local is a method within a method. It is only accessible within the containing method. In other words, a Local operation is not called by name, but by dataflow. It does not appear in the class Methods window.

By giving the*412* Local operation icon a descriptive name, the local serves a documentation function. In addition, locals are useful housecleaners: they help you to keep things simple in a case window.

The Prograph editor is intelligent enough to analyze the operations selected for the local and to create a Local operation with the correct number of terminals and roots. Furthermore, the roots and terminals of the newly specified Local method operation are correctly connected by datalinks to operations that remain outside the Local operations.
-----------------------------------------------------------

u Double-click the Make a Named Person local operation icon to open its case window. In its case window you see all the operations that disappeared from the Add method case window when the*654* *800* Opers to Local *808*menu item was selected.

u To pass the new named Person back out to the Add method for more processing, select the root of the //birth operation. Option-point the crosshair to a position just above the output bar, and Command-click. A terminal appears on the output bar connected by a datalink to the root of //birth.

u Close the Make a Named Person case window to return to the Add case window. A root has appeared on the Make a Named Person local operation. The next step is to take the new Person object on this root and store it in the People persistent list.

___________________________________________________________
*657*NOTE: A Persistent operation*827* in a case window provides access to persistent objects. If you create a root on a Persistent operation, when executed the Persistent operation outputs the stored value of the Persistent object along any datalinks connected to the root. If you create a terminal on the Persistent operation, when executed the Persistent *824*object takes on the value of any data or object arriving at the terminal.
-----------------------------------------------------------

u Slightly below and to the left of the Make a Named Person local operation, Command-click to place an unspecified operation.

u Select Persistent *803*from the Opers menu, type People, and press Return. A Persistent operation icon takes shape.

u Command-click in about the middle of the People persistent operation along its bottom edge to create a root. The selection highlight moves from the Persistent operation to the newly created root.

u Option-Command-click slightly below the Persistent operation to add an operation. Select Primitives from the ˙Info… dialog.

u Scroll to and select the*82* attach-r *837*item. After reading the description, select Name. Press Return to turn the generic operation into a fully formed attach-r operation. Your People persistent operation is now attached to the left terminal of the attach-r operation.

u To add the new Person object to the People persistent list, select the root of the Make a Named Person local and Option-point-click a datalink to the right terminal of the attach-r operation.

u To return the input list with its newly appended item to the People persistent, select the root of the attach-r operation and Option-Command-click to add an operation. Select Persistent from the Opers menu to transform the newly created operation into a Persistent operation. Type People and press Return. 

The input terminal here lets the People persistent take on the value of the list arriving from the attach-r operation.

u Close the Add case window and the ˙Info… dialog to return to the Add execution window.

u To accommodate your changes, the method performs a rollback to the input bar. Press Return twice. Double-click the root of the Make a Named Person local operation to inspect*492* the new Person object that exits the local. Press Cancel to close the Value window.

u Press Return to execute the first People persistent operation. Double-click the left terminal of the attach-r operation to confirm that the empty list of the People persistent is arriving as the input list for the attach-r operation.

u Dismiss the Value window and press Return to execute the attach-r operation and double-click the terminal of the second Persistent operation (which is now highlighted). The Value window that opens confirms that the once empty list now contains a single item, a Person. Double-click the Person list item icon in the right pane of the Value window. Inspect the Name attribute icon to confirm that this Person is named "Betty". 

u Close the Value windows and press Return twice to complete execution of the Add method. The execution window disappears.

Add a few more folks to your database. Give each new person a unique name. Double-click the terminal of the persistent People operation each time you step through the Add method. After adding a few new folks, the Value window on your People persistent list looks like this: 

The Folks Database application is now functioning as a database. The Add button is now adding new Person objects to the persistent People list.